package com.ruoyi.exam.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.exam.domain.ExamProvinceGrade;
import com.ruoyi.exam.service.IExamProvinceGradeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

/**
 * 省份信息Controller
 * 
 * @author wky
 * @date 2024-09-09
 */
@RestController
@RequestMapping("/exam/grade")
@Tag(name = "【省份信息】管理")
public class ExamProvinceGradeController extends BaseController
{
    @Autowired
    private IExamProvinceGradeService examProvinceGradeService;

    /**
     * 查询省份信息列表
     */
    @Operation(summary = "查询省份信息列表")
    @PreAuthorize("@ss.hasPermi('exam:grade:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExamProvinceGrade examProvinceGrade)
    {
        startPage();
        List<ExamProvinceGrade> list = examProvinceGradeService.selectExamProvinceGradeList(examProvinceGrade);
        return getDataTable(list);
    }

    /**
     * 导出省份信息列表
     */
    @Operation(summary = "导出省份信息列表")
    @PreAuthorize("@ss.hasPermi('exam:grade:export')")
    @Log(title = "省份信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExamProvinceGrade examProvinceGrade)
    {
        List<ExamProvinceGrade> list = examProvinceGradeService.selectExamProvinceGradeList(examProvinceGrade);
        ExcelUtil<ExamProvinceGrade> util = new ExcelUtil<ExamProvinceGrade>(ExamProvinceGrade.class);
        util.exportExcel(response, list, "省份信息数据");
    }

    /**
     * 获取省份信息详细信息
     */
    @Operation(summary = "获取省份信息详细信息")
    @PreAuthorize("@ss.hasPermi('exam:grade:query')")
    @GetMapping(value = "/{gradeId}")
    public AjaxResult getInfo(@PathVariable("gradeId") Long gradeId)
    {
        return success(examProvinceGradeService.selectExamProvinceGradeByGradeId(gradeId));
    }

    /**
     * 新增省份信息
     */
    @Operation(summary = "新增省份信息")
    @PreAuthorize("@ss.hasPermi('exam:grade:add')")
    @Log(title = "省份信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExamProvinceGrade examProvinceGrade)
    {
        return toAjax(examProvinceGradeService.insertExamProvinceGrade(examProvinceGrade));
    }

    /**
     * 修改省份信息
     */
    @Operation(summary = "修改省份信息")
    @PreAuthorize("@ss.hasPermi('exam:grade:edit')")
    @Log(title = "省份信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExamProvinceGrade examProvinceGrade)
    {
        return toAjax(examProvinceGradeService.updateExamProvinceGrade(examProvinceGrade));
    }

    /**
     * 删除省份信息
     */
    @Operation(summary = "删除省份信息")
    @PreAuthorize("@ss.hasPermi('exam:grade:remove')")
    @Log(title = "省份信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gradeIds}")
    public AjaxResult remove(@PathVariable( name = "gradeIds" ) Long[] gradeIds) 
    {
        return toAjax(examProvinceGradeService.deleteExamProvinceGradeByGradeIds(gradeIds));
    }
}
